<!DOCTYPE html>
<html lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>${_title}</title>

<!-- Bootstrap core CSS -->

<link href="${_css}/bootstrap.min.css" rel="stylesheet">

<link href="${_font}/css/font-awesome.min.css" rel="stylesheet">
<link href="${_css}/animate.min.css" rel="stylesheet">

<!-- Custom styling plus plugins -->
<link href="${_css}/custom.css" rel="stylesheet">
<link href="${_css}/icheck/flat/green.css" rel="stylesheet">
<link href="${_css}/datatables/tools/css/dataTables.tableTools.css"rel="stylesheet">
<link rel="stylesheet" href="${_css}/base.css">

<script src="${_js}/jquery.min.js"></script>
<script src="${_js}/resize.js"></script>
<script type="text/javascript" src="${_front_js}/jquery.page.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
          <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->
<style>
td a {
	cursor: pointer
}
</style>
</head>


<body style="background: #F7F7F7;">
	<div class="">
		<div class="row">
			<div class="col-md-12 col-sm-12 col-xs-12">
				<div class="x_panel">
					<div class="x_title">
						<h2>购买记录列表</h2>
						<div class="clearfix"></div>
					</div>
						<div class="pull-right">
							<button id="query" type="button" class="btn btn-info">查询</button>
							<button id="export" type="button" class="btn" style="color:#fff;background-color: #1A82C3;border-color: #1A82C3;">导出</button>
						</div>
			                <form class="form-horizontal" id="goodBuyForm">
								<fieldset>
									<div class="control-group">
										<div class="controls">
											<div class="input-prepend input-group">
												<span class="add-on input-group-addon">
													<i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
												</span>
												<input type="text" style="width: 200px" name="reservation" id="reservation" placeholder="请选择兑换时间段"
												class="form-control" value="<#if createTimeBegin?? & createTimeEnd??>${createTimeBegin}~${createTimeEnd}</#if>" />
											</div>
										</div>
									</div>
								</fieldset>
							</form>
						<div class="clearfix"></div>
					</div>
				</div>
				<div class="scroll">
					<div class="x_content">
						<table id="example" data-action="/admin/goodBuy/list?1=1"
							class="table table-striped responsive-utilities jambo_table">
							<thead>
								<tr class="headings">
									<th><input type="checkbox" class="tableflat"></th>
									<th>序号</th>
									<th>商品名称</th>
									<th>购买数量</th>
									<th>所需积分</th>
									<th>购买时间</th>
									<th>姓名</th>
									<th>电话</th>
									<th>地址</th>
									<th>状态</th>
									<th>发货单号</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody>
								<#if (pageInfo.pageList?size > 0)> 
									<#list pageInfo.pageList as model>
										<tr class="even pointer">
											<td class="a-center "><input type="checkbox"
												class="tableflat"></td>
											<td>${model_index+1}</td>
											<td><#if model.goodName?exists> ${model.goodName} </#if></td>
											<td><#if model.count?exists> ${model.count} </#if></td>
											<td><#if model.score?exists> ${model.score} </#if></td>
											<td>${(model.buyTime?string("yyyy-MM-dd HH:mm:ss"))!}</td>
											<td><#if model.username?exists> ${model.username} </#if></td>
											<td><#if model.phone?exists> ${model.phone} </#if></td>
											<td><#if model.address?exists> ${model.address} </#if></td>
											<td>
												<#if (model.status?exists) && (model.status==0)>未发货 </#if>
												<#if (model.status?exists) && (model.status==1)>已发货 </#if>
											</td>
											<td><#if model.code?exists> ${model.code} </#if></td>
											<td>
											<#if (model.status?exists) && (model.status==0)>
											<a class="btn-check btn-check1" data-id="${model.id}"
												href="javascript:;">发货</a> 
											<#else>
											<a class="btn-check"  href="javascript:void(0)">已经发货</a> 
											</#if>
											</td>
										</tr>
									</#list>
								<#else> 
								<tr class="even pointer">
									<td colspan="11">无记录</td>
								</tr>	
								</#if>
							</tbody>
						</table>
						<#if (pageInfo.pageList?size > 0)> <#include "../base/Page.ftl">
						</#if>
					</div>
				</div>
			</div>
			<br />
		</div>
	</div>


<script src="${_js}/bootstrap.min.js"></script>

<!-- bootstrap progress js -->
<script src="${_js}/progressbar/bootstrap-progressbar.min.js" type="text/javascript"></script>
<script src="${_js}/nicescroll/jquery.nicescroll.min.js" type="text/javascript"></script>
<!-- icheck -->
<script src="${_js}/icheck/icheck.min.js" type="text/javascript"></script>

<script src="${_js}/custom.js" type="text/javascript"></script>

<!-- PNotify -->
<script src="${_js}/notify/pnotify.core.js" type="text/javascript"></script>
<script src="${_js}/notify/pnotify.buttons.js" type="text/javascript"></script>
<script src="${_js}/notify/pnotify.nonblock.js" type="text/javascript" ></script>

<!-- daterangepicker -->
<script type="text/javascript" src="${_js}/datepicker/moment.min2.js"></script>
<script type="text/javascript" src="${_js}/datepicker/daterangepicker.js"></script>
<script type="text/javascript" src="${_front_js}/date.js"></script>

<script type="text/javascript" src="${_front_js}/layer/layer.js" ></script>
<script type="text/javascript" src="${_front_js}/layer/extend/layer.ext.js" ></script>
	<script type="text/javascript">
	 	$(document).ready(function(){
	        $('input.tableflat').iCheck({
	            checkboxClass: 'icheckbox_flat-green',
	            radioClass: 'iradio_flat-green'
	        });
	    });
	        
        $('#reservation').daterangepicker(null, function (start, end, label) {
            //console.log(start.toISOString(), end.toISOString(), label);
        });
        

		function initData(action) { 
	    	var reservation = $("#reservation").val();
	    	var reg = /^\d{4}[-]\d{2}[-]\d{2}~\d{4}[-]\d{2}[-]\d{2}$/;
	    	if(reservation !="" && !reg.test(reservation)){
				new PNotify({
			            	title: '操作提示',
			            	text: '时间格式错误！',
			            	delay: 3e3,
			            	type: 'error'
			        	});
			    return false;
			}
	    	if(reservation !=""){
	    		var splitChar = "~";
	    		if(reservation.indexOf(splitChar) != -1){
	    			var startTime = $.trim(reservation.split(splitChar)[0]);
	    			var endTime = $.trim(reservation.split(splitChar)[1]);
	    			action +="&startTime="+startTime;
	    			action +="&endTime="+endTime;
	    		}
	    	}
			window.location.href=action;
		} 
		
		$(".btn-info").click(function(){
			initData($("#example").attr('data-action'));
		});
		
		$(".btn-check1").click(function(){
			var id = $(this).attr("data-id");
			 layer.prompt({
			  title: '发送货物，填写快递订单号，并确认',
			  value:'订单号',
			  formType: 0 //prompt风格，支持0-2
			}, function(temp){
				if(temp == '订单号'){
					layer.closeAll();
					return;
				}
			  	revise(id,temp);
			});
		})
		function sendGood(){
			
		}
		
		function revise(id,temp){
			var id = id;
			var code = temp ; 
			$.ajax({
				  type: "POST",
                  url: '/admin/goodBuy/sendGood',
                  data:{"id":id,"code":code},
                  async: false,
                  success: function(result) {
                      if(result.code==-1){
                      layer.alert("发货成功！", function(index){
						    layer.close(index);
						    window.location="/admin/goodBuy/list"
						}); 
                      }else{
                      	layer.alert(result.msg);
                      }  
                  }
			});
		}
		
		$("#export").click(function(){
			var count=0;
			var ids=new Array();
			var status = "";
			$("tbody .tableflat").each(function(){
				if($(this).parent().hasClass('checked')){
					ids[count]=$(this).attr("data-id");
					count++;
				}
			})
	    	var reservation = $("#reservation").val();
	    	var reg = /^\d{4}[-]\d{2}[-]\d{2}~\d{4}[-]\d{2}[-]\d{2}$/;
	    	if(reservation !="" && !reg.test(reservation)){
				new PNotify({
			            	title: '操作提示',
			            	text: '时间格式错误！',
			            	delay: 3e3,
			            	type: 'error'
			        	});
			    return false;
			}
			var action="/admin/export/goodBuy?ids="+ids;
			
			$("#goodBuyForm").attr("method","post");
			$("#goodBuyForm").attr("action",action);
			$("#goodBuyForm").submit();
		});	
	
		var startTime = "<#if startTime?exists>${startTime}</#if>";
		var endTime = "<#if endTime?exists>${endTime}</#if>";
		if(startTime != "" && endTime != ""){
			document.getElementById("reservation").value=startTime+"~"+endTime;
		}	
	</script>
</body>

</html>

</html>